package com.atguigu.lease.web.app.controller.login;


import com.atguigu.lease.common.context.LoginUserContext;
import com.atguigu.lease.common.result.Result;

import com.atguigu.lease.web.app.service.LoginService;
import com.atguigu.lease.web.app.vo.user.CaptchaVo;
import com.atguigu.lease.web.app.vo.user.LoginVo;
import com.atguigu.lease.web.app.vo.user.UserInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "后台管理系统登录管理")
@RestController
@RequestMapping("/app/")
public class LoginController {
@Autowired
LoginService loginService;
    @Operation(summary = "获取图形验证码")
    @GetMapping("login/captcha")
    public Result<CaptchaVo> getCaptcha() {
        CaptchaVo captchaVo =  loginService.getCaptcha();
        return Result.ok(captchaVo);

    }

    @Operation(summary = "获取短信验证码")
    @GetMapping("login/getCode")
public Result getSMSCode(@RequestParam String phone) {
         loginService.getSMSCode(phone);
        return Result.ok();
    }
    @Operation(summary = "登录")
    @PostMapping("login")
    public Result<String> login(@RequestBody LoginVo loginVo) {
        String s=loginService.login(loginVo);
        return Result.ok(s);
    }

    @Operation(summary = "获取登陆用户个人信息")
    @GetMapping("info")
    public Result<UserInfoVo> info() {
        UserInfoVo userInfoVo=loginService.getUser(LoginUserContext.getUser().getUserId());
        return Result.ok(userInfoVo);
    }
}